import {Module} from '@nestjs/common';
import {createClient} from 'redis';
import { ConfigService } from '@nestjs/config';
import {RedisService} from './redis-cache.service';

@Module({
    providers:[
        RedisService,
        {
            provide:'REDIS_CLIENT',
            inject: [ConfigService],
            async useFactory(configService:ConfigService) {
                const client = createClient({
                    socket:{
                        host:configService.get('REDIS_HOST','127.0.0.1'),
                        port:configService.get('REDIS_PORT',6379)
                    }
                })
                await client.connect();
                return client
            }
        }
    ],
    exports:[RedisService]
})
export class RedisModule{}